package es.deusto.ingenieria.BlWhSquares;

import java.util.Vector;

import es.deusto.ingenieria.is.search.formulation.Operator;
import es.deusto.ingenieria.is.search.formulation.State;

public class MoveRobot2Squares extends Operator {
	
	private double cost=1;

	public double getCost() {
		return cost;
	}

	@Override
	protected State effect(State state) {
		BlWhSquaresEnvironment bl =  ((BlWhSquaresEnvironment) state).Clone();
		bl.setPosition(bl.getPosition() + 2);
		return bl;
	}

	@Override
	protected boolean isApplicable(State state) {
		
		//comprobar si ha llegado al final
		BlWhSquaresEnvironment bl = (BlWhSquaresEnvironment) state;
		
		
		if ((bl.getPosition()<bl.getSquares().size())&&(bl.getSquares().get(bl.getPosition()).equals("white"))) {
			return true;
		} else
			return false;
	}

	public MoveRobot2Squares() {
		super("Mover 2",1d);
		// TODO Auto-generated constructor stub
	}

	public MoveRobot2Squares(String arg0, double arg1) {
		super(arg0, arg1);
		// TODO Auto-generated constructor stub
	}

	public MoveRobot2Squares(String arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
	}

	public static void main(String[] args) {
		Vector<String> squares = new Vector<String>();
		squares.add("white");
		squares.add("white");
		squares.add("black");
		squares.add("white");
		squares.add("white");
		squares.add("black");
		
		BlWhSquaresEnvironment entorno = new BlWhSquaresEnvironment(squares, 0);
		System.out.println("Posicion inicial"+entorno.toString());
		MoveRobot2Squares m = new MoveRobot2Squares();
		if (m.isApplicable(entorno)) {
			System.out.println("Es aplicable");
			BlWhSquaresEnvironment entorno2=(BlWhSquaresEnvironment) m.effect(entorno);
			System.out.println("Posicion nueva"+ entorno2.toString());
		}
	}

}
